﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using MOJsdk;

namespace AndroidRemote
{
    /// <summary>
    /// Interaction logic for Settings.xaml
    /// </summary>
    public partial class Settings : UserControl
    {
        private IHost _host;
        private MojSystem _system;

        public Settings()
        {
            InitializeComponent();
            INI();
        }

        private void INI()
        {
            _host = MojHost.GetHost;
            _system = MojHost.GetHost.MoJSystem;

            INIStyle();
            INIEvents();
        }
        private void INIStyle()
        {
            ServerPort.Create(8082);
            ServerAdress.Create("NULL");
            ServerStatus.Create(false);

            _Grid.ApplyStyle("");

            _txt_port.ApplyStyle("");
            _txt_status.ApplyStyle("");
            _txt_title.ApplyStyle("");

            _lbl_port.ApplyStyle("");
            _lbl_status.ApplyStyle("");
        }
        private void INIEvents()
        {
            this.Loaded += delegate { FillVars(); };

            _txt_port.TextChanged += NewPort;
        }

        private void FillVars()
        {
            _txt_port.Text = ServerPort.Value().ToString();

            if (ServerStatus.Value())
            {
                string adress = ServerAdress.Value();
                string port = _txt_port.Text;

                string msg = string.Format("Server running on: \n{0}:{1}", adress, port);
                _txt_status.Text = msg;
            }
            else
            {
                string msg = "Restart MOJ to start server";
                _txt_status.Text = msg;
            }
        }

        private void ChangeServiceStatus(object sender, RoutedEventArgs e)
        {

        }
        private void NewPort(object sender, TextChangedEventArgs e)
        {

        }

        public static MojEnumVar<int> ServerPort
        { get { return new MojEnumVar<int>("PluginServer_ServerPort" , StorageType.UserVar); } }
        public static MojEnumVar<string> ServerAdress
        { get { return new MojEnumVar<string>("PluginServer_ServerAdress", StorageType.UserVar); } }
        public static MojEnumVar<bool> ServerStatus
        { get { return new MojEnumVar<bool>("PluginServer_ServerStatus", StorageType.UserVar); } }
    }
}
